package vip.xumy.admin.sys.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vip.xumy.admin.sys.pojo.UserItem;

/**
 * @author:mengyxu
 * @date:2020年3月17日
 */

@Mapper
public interface IUserItemMapper {

	static final String BASE_COLUMN = "id,user_id,item_name,item_desc,item_type,item_flag,add_user,add_time,status";

	@Select({ "<script>", "SELECT * FROM sys_user_item ", "<where>", "<if test='id != null'> AND id = #{id} </if>",
			"<if test='userId != null'> AND user_id = #{userId} </if>",
			"<if test='itemType != null'> AND item_type = #{itemType} </if>",
			"<if test='itemFlag != null'> AND item_flag = #{itemFlag} </if>",
			"<if test='addUser != null'> AND add_user = #{addUser} </if>",
			"<if test='status != null'> AND status = #{status} </if>", "</where>", "ORDER BY status ASC, add_time DESC",
			"<if test='limitStart != null'> LIMIT #{limitStart},#{size} </if>", "</script>" })
	List<UserItem> queryByExample(UserItem example);

	@Insert({ "INSERT INTO sys_user_item (", BASE_COLUMN, ") VALUES ",
			"(#{id}, {userId}, #{itemName}, #{itemDesc}, #{itemType}, #{itemFlag}, #{addUser}, #{addTime}, '0')" })
	void insert(UserItem item);

	@Insert({ "<script>", "INSERT INTO sys_user_item (", BASE_COLUMN, ") VALUES ",
			"<foreach collection='list' item='item' separator=','>",
			"(#{item.id}, {item.userId}, #{item.itemName}, #{item.itemDesc}, #{item.itemType}, ",
			"#{item.itemFlag}, #{item.addUser}, #{item.addTime}, '0') ", "</foreach>", "</script>" })
	void insertBatch(List<UserItem> items);

	@Update({ "UPDATE sys_user_item SET status = #{status} WHERE id = #{id}" })
	void update(UserItem item);

}
